package com.gopay.common.cps.dao.cbrmb.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.cbrmb.CbRmbIntlCardDishonorDAO;
import com.gopay.common.domain.cbrmb.internationalcard.CbRmbIntlCardDishonor;

/**
 * 跨境人民币 外卡拒付辅助表DAO实现类
 * @CbRmbIntlCardDishonorDAOImpl.java
 * @author lailingyu
 * @2017-11-06 下午5:44:55  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository(value = "cbRmbIntlCardDishonorDAO")
public class CbRmbIntlCardDishonorDAOImpl extends BaseDAOImpl<CbRmbIntlCardDishonor, Long> implements CbRmbIntlCardDishonorDAO {

	@Override
	public List<CbRmbIntlCardDishonor> findByGopayOrderId(String gopayOrderId) {
		String hql = "from CbRmbIntlCardDishonor where gopayOrderId=:gopayOrderId";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("gopayOrderId", gopayOrderId);
		return findByHql(hql, param);
	}

	@Override
	public CbRmbIntlCardDishonor findByGopayOrderIdAndDishonorTime(String gopayOrderId, String dishonorTime) {
		String hql = "from CbRmbIntlCardDishonor where gopayOrderId=:gopayOrderId and dishonorTime=to_date(:dishonorTime, 'yyyy-MM-dd hh24:mi:ss')";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("gopayOrderId", gopayOrderId);
		param.put("dishonorTime", dishonorTime);
		List<CbRmbIntlCardDishonor> list = findByHql(hql, param);
		if (list != null && list.size() > 0) {
			return list.get(0);
		} else {
			return null;
		}
	}

	@Override
	public List<CbRmbIntlCardDishonor> findByGopayOrderIdAndTranType(String gopayOrderId, String tranType) {
		String hql = "from CbRmbIntlCardDishonor where gopayOrderId=:gopayOrderId and tranType=:tranType";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("gopayOrderId", gopayOrderId);
		param.put("tranType", tranType);
		return findByHql(hql, param);
	}

	@Override
	public CbRmbIntlCardDishonor findByDishonorOrderId(String dishonorOrderId) {
		String hql = "from CbRmbIntlCardDishonor where dishonorOrderId=:dishonorOrderId";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("dishonorOrderId", dishonorOrderId);
		List<CbRmbIntlCardDishonor> list = findByHql(hql, param);
		if (list != null && list.size() > 0) {
			return list.get(0);
		} else {
			return null;
		}
	}

}
